package clinicapoo.services;

import clinicapoo.dao.Transaction;
import clinicapoo.exceptions.ApplicationException;
import clinicapoo.factory.DAO;
import clinicapoo.model.Consulta;

/**
 *
 * @author Fabio Montezuma
 */
public class ConsultaServices extends BaseServices
{
    public void cadastrar(Consulta c) throws ApplicationException
    {
        log.debug(c.toString());

        Transaction tx = null;
        try
        {
            tx = new Transaction();
            DAO.consulta.cadastrar(c);
            tx.commit();
            log.info("Consulta cadastrada com sucesso: {}", c.toString());
        }
        catch (Exception e)
        {
            log.error(e.getMessage(), e);
            tx.rollback();
            throw new ApplicationException("Ocorreu um erro inesperado no cadastro de consulta.", e);
        }
    }
}
